package sc.love.boot.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sc.love.boot.socket.SocketServer;

import java.io.IOException;

/**
 * @ClassName SocketController
 * @Description webSocket
 * @Author 15393
 * @Date 2020/6/2 16:15
 * @Version V1.0
 */
@Controller
public class SocketController {

    @GetMapping("/im1")
    public String im1(){
        return "socket/ImSocket1";
    }
    @GetMapping("/im2")
    public String im2(){
        return "socket/ImSocket2";
    }

    @GetMapping("/im/send")
    @ResponseBody
    public String send(String userId,String message){
        try {
            SocketServer.sendMessage(userId,message);
        } catch (IOException e) {
            e.printStackTrace();
            return e.getMessage();
        }
        return "success";
    }
}